package com.example.list;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import com.example.utils.ToastUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class GetResourceActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_resource);
        List<Map<String, Object>> list=  getAssetsImgge();
        ToastUtil.showToast("银行icon数量："+list.size());
    }
    public List getAssetsImgge() {
        List<Map<String, Object>> cateList = new ArrayList<Map<String, Object>>();
        String[] list_image = null;
        Hashtable<String, String> imgBankHash = null;
        try {
//得到assets/processedimages/目录下的所有文件的文件名，以便后面打开操作时使用
            list_image =getResources().getAssets().list("yzzz");
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        if (list_image.length>0) {
            imgBankHash = new Hashtable<>();
            imgBankHash.put("Industrial_and_Commercial_Bank_of_China.png", "5200");
            imgBankHash.put("China_Everbright_Bank.png", "5800");
            imgBankHash.put("Guangdong_Development_Bank.png", "6200");
            imgBankHash.put("Huaxia_Bank.png", "5900");
            imgBankHash.put("China_Construction_Bank.png", "5000");
            imgBankHash.put("Bank_of_Communications.png", "5400");
            imgBankHash.put("China_Minsheng_Bank.png", "6000");
            imgBankHash.put("Agricultural_Bank_of_China.png", "5100");
            imgBankHash.put("Shanghai_Pudong_Development_Bank.png", "6300");
            imgBankHash.put("China_Citic_Bank.png", "5600");
            imgBankHash.put("Bank_of_Shanghai.png", "7100");
            imgBankHash.put("Industrial_Bank.png", "5700");
            imgBankHash.put("Postal_Savings_Bank_of_China.png", "8500");
            imgBankHash.put("China_Merchants_Bank.png", "5500");
            imgBankHash.put("Bank_of_China.png", "5300");
            imgBankHash.put("Ping_An_Bank.png", "6100");
        }

        InputStream open = null;
        try {
            for (int i = 0; i < list_image.length; ++i) {
                String temp = "yzzz/" + list_image[i];
                open = getAssets().open(temp);
                Bitmap bitmap = BitmapFactory.decodeStream(open);
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("name", imgBankHash.get(list_image[i]));
                map.put("img", bitmap);
                cateList.add(map);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (open != null) {
                try {
                    open.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return cateList;
    }
}